<template>
    <div class='dialog'>
        <div class='newAdd dialog-con updateChannelInfo'>
          <split-vertical title="更新渠道信息"></split-vertical>
            <div class='channelContent'>
              <label><span>*</span>渠道名称:</label><el-input placeholder="必输项" v-model="add.channelName"></el-input><br>
              <label><span>*</span>渠道地址:</label><el-input placeholder="必输项" v-model="add.channelAddress"></el-input> <br>
              <label><span>*</span>渠道联系人:</label><el-input placeholder="必输项" v-model="add.channelContact"></el-input><br>
              <label><span>*</span>联系人电话:</label><el-input placeholder="必输项" v-model="add.channelMobile" @blur="contactPhone(add.channelMobile)"></el-input>
              <p v-if="dis_phone">*请输入正确的手机号</p>
            </div>
            <div class="confirm">
                <el-button @click="confirm(add.id)" type="primary" style="margin:0 20px;" size="medium">确定</el-button>
                <el-button @click="cancel"  size="medium">取消</el-button>
            </div>
        </div>
    </div>
</template>
<script>
import SplitVertical from "components/common/SplitVertical"
import api from "js/service";
import regular from 'js/regular'
export default {
  inject: ["reload"],
  components:{
      SplitVertical
  },
  data() {
    return {
      companyCode: "", //  公司编码
      channelContent: "", //  公司名称
      companyDeputy: "", //公司法人代表
      companyAccountName: "", //我司对公账户
      accountBank: "", //开户行
      accountNo: "", //开户行账户
      userId: 1, //录入人
      show: true,
      dis_phone:false
    };
  },
  props: {
    add: {}
  },
  methods: {
    confirm(id) {
      if(!regular.phoneNumCheck(this.add.channelMobile)){
        return this.dis_phone=true;
      }else{
        this.dis_phone=false;
      }
      let parmas = {
        channelName: this.add.channelName,
        channelAddress: this.add.channelAddress,
        channelMobile: this.add.channelMobile,
        channelContact: this.add.channelContact,
        id: id
      };
      let success = data => {
        if (data.code == "OK") {
          this.$message.success("保存成功");
          this.show = false;
          this.reload();
          this.$emit("closeDialog");
        }else {
          this.$message.error(data.msg);
        }
      };
      api.channelUpdate(parmas, success);
    },
    cancel() {
      this.$emit("closeDialog");
    },
    contactPhone(channelMobile){
      if(!regular.phoneNumCheck(channelMobile)){
        this.dis_phone=true;
      }else{
        this.dis_phone=false;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.updateChannelInfo {
  width: 500px;
  height: 450px;
  .companynews {
    h2 {
      height: 60px;
      line-height: 60px;
      text-indent: 20px;
      font-size: 20px;
    }
  }
  .channelContent {
    margin-left: 5%;
    span{
      color:red;
    }
    label {
      width: 110px;
      font-size:14px;
      display: inline-block;
      color:#606266;
    }
    .el-input{
      height: 40px;
      width:300px;
      margin: 20px 0 10px 0;
      font-size:14px;
      color:#606266;
    }
    p{
      margin-left:22%;
      color:red;
      font-size:12px;
    }
  }
  .confirm {
     text-align: center;
     padding-top: 30px;
  }
}
</style>

